package cn.iocoder.yudao.module.resource.api;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.resource.api.model.CosplayDTO;
import cn.iocoder.yudao.module.resource.controller.admin.cosplay.vo.LmCosplayPageReqVO;
import cn.iocoder.yudao.module.resource.controller.admin.cosplay.vo.LmCosplayRespVO;
import cn.iocoder.yudao.module.resource.dal.dataobject.cosplay.LmCosplayDO;
import cn.iocoder.yudao.module.resource.service.cosplay.LmCosplayService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;

@Service
public class CosplayApiImpl implements ICosplayApi {
    @Resource
    private LmCosplayService cosplayService;

    @Override
    public CosplayDTO getCosplay(Integer id) {
        final CosplayDTO dto = BeanUtils.toBean(cosplayService.getCosplay(id), CosplayDTO.class);
        if (dto != null) {
            cosplayService.attachDTORelationUrl(Arrays.asList(dto));
        }
        return dto;
    }


    @Override
    public void validateCosplayExists(Integer id) {
        cosplayService.validateCosplayExists(id);
    }

    @Override
    public List<CosplayDTO> getAllCosplay(List<String> showLocation) {
        final LmCosplayPageReqVO reqVO = new LmCosplayPageReqVO();
        reqVO.setShowLocation(showLocation);
        final PageResult<LmCosplayDO> pageResult = cosplayService.getCosplayPage(reqVO);
        final List<CosplayDTO> dtoList = BeanUtils.toBean(pageResult.getList(), CosplayDTO.class);
        cosplayService.attachDTORelationUrl(dtoList);
        return dtoList;
    }

}
